	
	* Table A11
	/* Impact of SFRs on Educational Attainment and Civic Engagement: 
	Stacked DD Estimates */

		
		// First create a sample of control states
		clear all
		set more off
	
		use "C:\Users\EAsker\Desktop\ABR\data\ABR_final_data"
	
		keep if CSFR_year_BJH==.
		
		save "C:\Users\EAsker\Desktop\ABR\data\control_final_data", replace

		
		// Second append control sample to reform state one by one
		use "C:\Users\EAsker\Desktop\ABR\data\ABR_final_data"
		
		keep if CSFR_year_BJH~=.
		egen cohort=group(CSFR_year_BJH)
		
		// 14 represents number of reform years
		
		forvalues i=1/14 {
		    
			append using "C:\Users\EAsker\Desktop\ABR\data\control_final_data"
			replace cohort=`i' if cohort==.
			
		}
		
		save "C:\Users\EAsker\Desktop\ABR\data\dd_final_data", replace
		
		// dropping previous fixed effects to add cohort to each of them
		
		drop  statexsurvey_quartile quartilexstate quartilexsurvey
		
		egen statexsurvey_quartile=concat(fipst survey cohort)
		destring statexsurvey_quartile, replace
		label var statexsurvey_quartile "State by Survey and Cohort FE"
		
		egen quartilexstate=concat(fipst qrdinc80_b cohort)
		destring quartilexstate, replace
		label var quartilexstate "State by Quartile and Cohort FE"
		
		egen quartilexsurvey=concat(survey qrdinc80_b cohort)
		destring quartilexsurvey, replace
		label var quartilexsurvey "Quartile by Survey and Cohort FE"
		
		egen statexcohort=concat(fipst cohort)
		destring statexcohort, replace
		
		label var statexcohort "State by Cohort FE"
		
		save "C:\Users\EAsker\Desktop\ABR\data\dd_final_data", replace
	
		************************************************************************
		clear all
		set more off
	
		*** Using sample 
		use "C:\Users\EAsker\Desktop\ABR\data\dd_final_data"
		
		drop if qrdinc80_b==2|qrdinc80_b==3
		
		****Baseline controls
		replace fam_inc=. if fam_inc==99|fam_inc==97|fam_inc==0
		gen ln_fam_inc=log(fam_inc)
		
		gen miss_mot_hs=1 if mot_hs==.
		replace miss_mot_hs=0 if mot_hs~=.
		replace mot_hs=0 if mot_hs==.
	
		gen miss_fat_hs=1 if fat_hs==.
		replace miss_fat_hs=0 if fat_hs~=.
		replace fat_hs=0 if fat_hs==.
	   
		gen miss_fam_inc=1 if ln_fam_inc==.
		replace miss_fam_inc=0 if ln_fam_inc~=.
		replace ln_fam_inc=0 if ln_fam_inc==.
	
		gen miss_female=1 if female==.
		replace miss_female=0 if female~=.
		replace female=0 if female==.
	    sort  survey wave sch_id
		
		gen miss_not_white=1 if not_white==.
		replace miss_not_white=0 if not_white~=.
		replace not_white=0 if not_white==.
		
		egen m_weight=mean(weight), by(survey wave sch_id) 
	    replace weight=m_weight if (weight==.|weight==0)&m_weight~=0	
		
		gen log_income=log(income)
		
		gen income_0=income
		replace income_0=. if income_0==0
		
		gen pos_income_dummy=.
		replace pos_income_dummy=1 if income>0&income~=.
		replace pos_income_dummy=0 if income==0
		
		replace vlntry_hours=200 if vlntry_hours>=200&vlntry_hours~=.

		******** Drop 2nd and 3rd quartiles *****************
		drop if qrdinc80_b==2|qrdinc80_b==3
		
		local controls_civic " miss_mot_hs miss_fam_inc miss_not_white miss_female mot_hs ln_fam_inc not_white female "
		
		foreach y of varlist high_school post_scndry vltnry_prtcptn ///
		vlntry_hours register_vote {
	   	
		reghdfe `y' qr1_sfr_exp_trend_BHJ  qr1_sfr_BHJ  `controls_civic' ///
		if wave==2 , absorb ( statexsurvey_quartile quartilexstate quartilexsurvey) ///
		cluster (quartilexstate) 
	
	outreg2 using Table_2.xls, append ctitle(`y') bdec(4) nonotes nocons ///
		keep(qr1_sfr_exp_trend_BHJ  qr1_sfr_BHJ) ///
		addtext(Control, YES, State by Survey FE, YES, ///
		Quartile by State FE, YES, Quartile by Survey FE, YES) 
				 
	}
	
	
	
	
	